//
//  YSTabBarViewController.m
//  HubayMe1
//
//  Created by apple on 16/12/16.
//  Copyright © 2016年 Global Barter. All rights reserved.
//

#import "YSTabBarViewController.h"
#import "YSMeViewController.h"
#import "YSHomeViewController.h"
#import "YSShoppingCartViewController.h"
#import "YSClassificationViewController.h"

#import "RTRootNavigationController.h"

@interface YSTabBarViewController ()

@end

@implementation YSTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 1 添加所有的子控制器：有多少个按钮，就有多少个子控制器
    [self setupAllChildViewController];
    
    // 2.设置tabBar上所有按钮的内容:由对应的子控制器的tabBarItem属性决定
    [self setupAllTabBarButton];
    
}

// 添加所有的子控制器
-(void)setupAllChildViewController{
    
    //首页
    YSHomeViewController *homeVC = [[YSHomeViewController alloc]init];
//    homeVC.view.backgroundColor = [UIColor redColor];
    homeVC.title = @"首页";
    RTRootNavigationController *nav0 = [[RTRootNavigationController alloc]initWithRootViewController:homeVC];
    [self addChildViewController:nav0];
    
    //分类
    YSClassificationViewController *classVC = [[YSClassificationViewController alloc]init];
//    classVC.view.backgroundColor = [UIColor orangeColor];
    classVC.title = @"分类";
    RTRootNavigationController *nav1 = [[RTRootNavigationController alloc]initWithRootViewController:classVC];
    [self addChildViewController:nav1];
    
    //购物车
    YSShoppingCartViewController *shoppingVC = [[YSShoppingCartViewController alloc]init];
//    shoppingVC.view.backgroundColor = [UIColor greenColor];
    shoppingVC.title = @"购物车";
    RTRootNavigationController *nav2 = [[RTRootNavigationController alloc]initWithRootViewController:shoppingVC];
    [self addChildViewController:nav2];
    
    //我的
    YSMeViewController *meVC = [[YSMeViewController alloc]init];
//    meVC.view.backgroundColor = [UIColor blueColor];
    //meVC.title = @"我的";
    RTRootNavigationController *nav3 = [[RTRootNavigationController alloc]initWithRootViewController:meVC];
    [self addChildViewController:nav3];
}

// 设置tabBar上所有按钮的内容
- (void)setupAllTabBarButton
{
    // 首页:0
    // 获取第0个子控制器
    UINavigationController *nav0 = self.childViewControllers[0];
    nav0.tabBarItem.title = @"首页";
    nav0.tabBarItem.image = [UIImage imageNamed:@"tabBar_CJHomeTreasure"];
    nav0.tabBarItem.selectedImage = [UIImage imageWithOriginalImageName:@"tabBar_CJHomeTreasure_Highlight"];
    
    // 分类
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"分类";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_CJShoppingCar"];
    nav1.tabBarItem.selectedImage = [UIImage imageWithOriginalImageName:@"tabBar_CJShoppingCar_Highlight"];
    
    //购物车
    UINavigationController *nav3 = self.childViewControllers[2];
    nav3.tabBarItem.title = @"购物车";
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_CJNearbyDrugstore"];
    nav3.tabBarItem.selectedImage = [UIImage imageWithOriginalImageName:@"tabBar_CJNearbyDrugstore_Highlight"];
    
    // 我的
    UINavigationController *nav4 = self.childViewControllers[3];
    nav4.tabBarItem.title = @"我的";
    nav4.tabBarItem.image = [UIImage imageNamed:@"tabBar_CJMy"];
    nav4.tabBarItem.selectedImage = [UIImage imageWithOriginalImageName:@"tabBar_CJMy_Highlight"];
}

@end
